#include <iostream>
#include <string>
#include <vector>
#include <chrono>
#include <ctime>
#include <thread>
#include <mutex>

using namespace std;
mutex g_lock;

void tfunc (int i)
{	
	g_lock.lock();
	cout << "In thread : " << i << endl;
	g_lock.unlock();
}

int main (void)
{
	const int tn(500);
	auto start = chrono::system_clock::now();
	thread tha[tn];
	for (int i=0;i<tn;i++)
		tha[i] = thread(tfunc, i);

	for (int i=0;i<tn;i++)
		tha[i].join();
	this_thread::sleep_for(chrono::seconds(1));
	auto end = chrono::system_clock::now();
//	typedef chrono::duration<int, std::centi> deci;
	auto elapsed_deci = chrono::duration_cast<chrono::milliseconds>(end-start).count();
	auto elapsed_s = chrono::duration_cast<chrono::seconds>(end-start).count();
	cout << "Threads duration: " << elapsed_deci << " millisecond, " << elapsed_s << " seconds." << endl;
	auto t1 = chrono::system_clock::to_time_t(chrono::system_clock::now());
	auto today = ctime(&t1);
	cout << "Today: " << today << endl;
	cout << "main thread end" << endl;
	return 0;
}


